package com.anysoft.home.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.anysoft.HostConstant;
import com.anysoft.MentorConst;
import com.anysoft.R;
import com.anysoft.base.BaseFragment;
import com.anysoft.bean.QueryFundInfoBean;
import com.anysoft.bean.QueryRiskLevelBean;
import com.anysoft.bean.QueryUserAssetsBean;
import com.anysoft.bean.UserBean;
import com.anysoft.event.InterfaceCallback;
import com.anysoft.home.HomeActivity;
import com.anysoft.user.UserSettingActivity;
import com.anysoft.utils.AnalyticsEventUtils;
import com.anysoft.utils.StringUtils;
import com.anysoft.view.PullToRefreshView;
import com.anysoft.web.AssetsActivity;
import com.anysoft.web.AssetsFundActivity;
import com.anysoft.web.AssetsFundDetailActivity;
import com.anysoft.web.AssetsInTransitActivity;
import com.anysoft.web.CalendarFinanceActivity;
import com.anysoft.web.FixInvestmentAllActivity;
import com.anysoft.web.FundDetailActivity;
import com.anysoft.web.SearchTradeNewActivity;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * @ProjectName：gy_fund-android
 * @ClassDescription：
 * @CreateUser： yanbin
 * @CreateTime：2017-02-27 16:12
 * @ModifiedUser：
 * @ModifiedTime：
 * @ModifiedRemark：
 */

public class AccountTab extends BaseFragment implements PullToRefreshView.OnHeaderRefreshListener {
    private final static String TAG = "AccountTab";

    /**
     * 下拉刷新控件
     */
    @BindView(R.id.pullToRefreshView)
    PullToRefreshView pullToRefreshView;

    /**
     * 用户头像
     */
    @BindView(R.id.civ_account_user_head)
    CircleImageView civ_account_user_head;
    /**
     * 用户名称
     */
    @BindView(R.id.tv_user_name)
    TextView tv_user_name;
    @BindView(R.id.rl_account_title)
    RelativeLayout rl_account_title;


    /**
     * 用户未进行风险评测
     */
    @BindView(R.id.tv_no_risk)
    TextView tv_no_risk;

    /**
     * 资产日历
     */
    @BindView(R.id.ll_calendar)
    LinearLayout ll_calendar;
    /**
     * 资产日历
     */
    @BindView(R.id.tv_rili_month)
    TextView tv_rili_month;
    /**
     * 资产日历
     */
    @BindView(R.id.tv_rili_day)
    TextView tv_rili_day;
    /**
     * 总资产-整数
     */
    @BindView(R.id.tv_total_account_val)
    TextView tv_total_account_val;
    /**
     * 总资产-小数
     */
    @BindView(R.id.tv_total_account_decimal_val)
    TextView tv_total_account_decimal_val;
    /**
     * 是否显示总资产
     */
    @BindView(R.id.image_is_show_total_account)
    ImageView image_is_show_total_account;
    /**
     * 昨日收益
     */
    @BindView(R.id.tv_yesterday_income_val)
    TextView tv_yesterday_income_val;
    /**
     * 累计收益 key
     */
    @BindView(R.id.tv_total_income_key)
    TextView tv_total_income_key;
    /**
     * 累计收益
     */
    @BindView(R.id.tv_total_income_val)
    TextView tv_total_income_val;
    /**
     * 在途资产个数
     */
    @BindView(R.id.tv_open_ztzc_val)
    TextView tv_open_ztzc_val;
    /**
     * 现金快线值
     */
    @BindView(R.id.tv_xjkx_val)
    TextView tv_xjkx_val;
    /**
     * 超级现金快线值
     */
    @BindView(R.id.tv_cjxjkx_val)
    TextView tv_cjxjkx_val;
    /**
     * 智慧
     */
    @BindView(R.id.tv_zh_val)
    TextView tv_zh_val;
    /**
     * 基金
     */
    @BindView(R.id.tv_jj_val)
    TextView tv_jj_val;
    @BindView(R.id.rl_jj_val)
    RelativeLayout rl_jj_val;
    /**
     * 定投
     */
    @BindView(R.id.tv_dt_val)
    TextView tv_dt_val;
    /**
     * 交易查询
     */
    @BindView(R.id.ll_transaction_search)
    LinearLayout ll_transaction_search;

    private View root;
    /**
     * 总资产
     */
    private String sTotalAccount;
    private HomeActivity activity;

    String fundstateDescription_xjkx, fundstateDescription_cjxjkx;
    String fundName_xjkx, fundName_cjxjkx;
    String fundState_xjkx, fundState_cjxjkx, fundType_xjkx, fundType_cjxjkx, shareClass_xjkx, shareClass_cjxjkx, fundrisklevel_xjkx, fundrisklevel_cjxjkx;

    /**
     * 记录当前登录用户编号  如果切换用户
     */
    private String currLoginFundCustomerNo;


    private String sYesterDayIncome = "";//昨日收益
    private String sTtotalincome = "";//累计收益
    private String sHomeCashTotal = "";//现金快线 总额
    private String sHomeSuperCashTotal = "";//超级现金快线 总额
    private String sZHAccount = "";//智慧 tv_zh_val
    private String sJJAccount = "";//基金 tv_jj_val

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (HomeActivity) context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_account_tab_new, container, false);
        ButterKnife.bind(this, root);
        EventBus.getDefault().register(this);
        pullToRefreshView.setOnHeaderRefreshListener(this);
        pullToRefreshView.setIsCancleLoadMore();
        getCurrentDate();

        if (!activity.mentorApplication.needLogin()) {
            parseJson(getQueryUserAssetsBean());
            parseJson_level(getQueryRiskLevelBean());
        }
        return root;
    }

    public final static char[] upper = "零一二三四五六七八九十".toCharArray();

    private void getCurrentDate() {
        Date d = new Date();
        System.out.println(d);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateNowStr = sdf.format(d);
        StringBuilder sb = new StringBuilder();
        int month = Integer.parseInt(dateNowStr.substring(4, 6));
        if (month <= 10) {
            sb.append(upper[month]);
        } else {
            sb.append("十").append(upper[month % 10]);
        }
        sb.append("月");//拼接月
        tv_rili_month.setText(sb.toString());
        tv_rili_day.setText(dateNowStr.substring(6, 8));
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!StringUtils.isNullOrEmpty(currLoginFundCustomerNo) && !currLoginFundCustomerNo.equals(activity.getFundCustomerNo())) {
            initControData();
        }
        currLoginFundCustomerNo = activity.getFundCustomerNo();
        initData(false);
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    /**
     * 初始化控件数据为--
     */
    private void initControData() {

        String sDefaultData = "--";
        sTotalAccount = sDefaultData;

        civ_account_user_head.setImageResource(R.mipmap.icon_user);
        tv_user_name.setText("");
        sYesterDayIncome = sDefaultData;//昨日收益
        sTtotalincome = sDefaultData;//累计收益
        sHomeCashTotal = sDefaultData;//现金快线 总额
        sHomeSuperCashTotal = sDefaultData;//超级现金快线 总额
        sZHAccount = sDefaultData;//智慧 tv_zh_val
        sJJAccount = sDefaultData;//基金 tv_jj_val


        tv_no_risk.setVisibility(View.GONE);
        tv_yesterday_income_val.setText(sDefaultData);
        tv_total_income_val.setText(sDefaultData);
        tv_total_account_decimal_val.setText("");
        tv_total_account_val.setText("" + sTotalAccount);
        tv_open_ztzc_val.setText(sDefaultData + "个");//客户在途资产数量
        tv_dt_val.setText(sDefaultData + "个");//客户总定投数量
        tv_zh_val.setText(sDefaultData);
        tv_jj_val.setText(sDefaultData);

        fundName_xjkx = null;
        fundState_xjkx = null;
        fundstateDescription_xjkx = null;
        fundName_cjxjkx = null;
        fundState_cjxjkx = null;
        fundstateDescription_cjxjkx = null;
        fundType_xjkx = null;
        fundType_cjxjkx = null;
        shareClass_xjkx = null;
        shareClass_cjxjkx = null;
        fundrisklevel_xjkx = null;
        fundrisklevel_cjxjkx = null;
        tv_xjkx_val.setText("" + sDefaultData + "");
        tv_cjxjkx_val.setText("" + sDefaultData);
    }

    private void initData(boolean isPullRefresh) {


        if (activity.mentorApplication.needLogin()) {
            refreshComplete();
            if (((HomeActivity) activity).iCurrSelectIndex == 3) {
                ((HomeActivity) activity).setTabSelection(((HomeActivity) activity).iUpSelectIndex);
            }
        } else {
            tv_user_name.setText(activity.mentorApplication.userBean.getUserName());
            try {
                setIsShowTotalAccount(((HomeActivity) activity).getShowTotalAccountStatus());
            } catch (Exception e) {
                e.printStackTrace();
            }
            UserBean bean = activity.findUser(activity.findUserId());
            String pathUrl = "";
            if (bean != null) {
                pathUrl = bean.getUserImgPath();
            }
            if (!TextUtils.isEmpty(pathUrl)) {
                Logger.t("pathUrl").d(pathUrl);
                Bitmap bitmap = getDiskBitmap(pathUrl);
                if (bitmap != null) {
                    civ_account_user_head.setImageBitmap(bitmap);
                }
            } else {
                if ("0".equals(bean.getSex())) {//女
                    civ_account_user_head.setImageResource(R.mipmap.icon_user_w);
                } else if ("1".equals(bean.getSex())) {//男
                    civ_account_user_head.setImageResource(R.mipmap.icon_user_m);
                } else {
                    civ_account_user_head.setImageResource(R.mipmap.icon_user);
                }
            }
            if (isPullRefresh) {
                queryRiskLevelHome();
                queryFundInfoHome(HostConstant.XJKJ_CODE);
                queryFundInfoHome(HostConstant.CJXJKJ_CODE);
                queryUserAssetsHome();
            }
        }
    }

    private Bitmap getDiskBitmap(String pathString) {
        Bitmap bitmap = null;
        try {
            File file = new File(pathString);
            if (file.exists()) {
                bitmap = BitmapFactory.decodeFile(pathString);
                System.out.println("bitmap存在");
            }
        } catch (Exception e) {
            System.out.println("bitmap不存在");
        }
        return bitmap;
    }

    @OnClick({R.id.ll_total_account_container, R.id.ll_calendar,
            R.id.image_is_show_total_account, R.id.rl_is_show_total_account, R.id.rl_ztcl_layout,
            R.id.rl_xjkx_layout, R.id.rl_cjxjkx_layout, R.id.rl_zh_layout,
            R.id.rl_dt_layout, R.id.ll_transaction_search, R.id.rl_jj_val, R.id.rl_total_incom_layout,
            R.id.civ_account_user_head, R.id.tv_user_name, R.id.rl_account_title})
    public void onClick(View v) {
        if (activity != null && !activity.isFastDoubleClick()) {
            switch (v.getId()) {
                case R.id.ll_calendar://日历
                    AnalyticsEventUtils.toClickCalendarEvent(getActivity());
                    activity.startActivity(new Intent().setClass(activity, CalendarFinanceActivity.class));
                    break;
                case R.id.ll_total_account_container://总资产
                    AnalyticsEventUtils.toClickTotalAssetEvent(getActivity());
                    activity.startActivity(new Intent().setClass(activity, AssetsFundActivity.class));
                    break;
                case R.id.image_is_show_total_account://是否显示总资产
                case R.id.rl_is_show_total_account://是否显示总资产
                    try {
                        ((HomeActivity) activity).isShowTotalAccount();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case R.id.rl_ztcl_layout://在途资产
                    activity.startActivity(new Intent().setClass(activity, AssetsInTransitActivity.class));
                    break;
                case R.id.rl_xjkx_layout://现金快线
                    BigDecimal decimalXJKX = new BigDecimal(0);
                    try {
                        decimalXJKX = new BigDecimal(sHomeCashTotal.replaceAll(",", ""));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNullOrEmpty(fundName_xjkx) || decimalXJKX.doubleValue() == 0) {
                        startFundDatile(getXJKJDataBean());
                        return;
                    }
                    Intent intent = new Intent(activity, AssetsFundDetailActivity.class);
                    intent.putExtra("openType", "param");
                    intent.putExtra("fundcode", HostConstant.XJKJ_CODE);
                    intent.putExtra("fundname", fundName_xjkx);
                    intent.putExtra("fundState", fundState_xjkx);
                    intent.putExtra("fundstateDescription", fundstateDescription_xjkx);
                    intent.putExtra("fundstateid",
                            TextUtils.isEmpty(fundState_xjkx) ? "" : fundState_xjkx);
                    intent.putExtra("fundType",
                            TextUtils.isEmpty(fundType_xjkx) ? "" : fundType_xjkx);
                    intent.putExtra("shareClass",
                            TextUtils.isEmpty(shareClass_xjkx) ? "" : shareClass_xjkx);
                    intent.putExtra("fundrisklevel",
                            TextUtils.isEmpty(fundrisklevel_xjkx) ? "" : fundrisklevel_xjkx);
                    activity.startActivity(intent);
                    break;
                case R.id.rl_cjxjkx_layout://超级现金快线
                    BigDecimal decimalCJXJKX = new BigDecimal(0);
                    try {
                        decimalCJXJKX = new BigDecimal(sHomeSuperCashTotal.replaceAll(",", ""));//sHomeSuperCashTotal
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (StringUtils.isNullOrEmpty(fundName_cjxjkx) || decimalCJXJKX.doubleValue() == 0) {
                        startFundDatile(getCJXJKJDataBean());
                        return;
                    }
                    Intent intent_cj = new Intent(activity, AssetsFundDetailActivity.class);
                    intent_cj.putExtra("openType", "param");
                    intent_cj.putExtra("fundcode", HostConstant.CJXJKJ_CODE);
                    intent_cj.putExtra("fundname", fundName_cjxjkx);
                    intent_cj.putExtra("fundState", fundState_cjxjkx);
                    intent_cj.putExtra("fundstateDescription", fundstateDescription_cjxjkx);
                    intent_cj.putExtra("fundType",
                            TextUtils.isEmpty(fundType_cjxjkx) ? "" : fundType_cjxjkx);
                    intent_cj.putExtra("fundstateid",
                            TextUtils.isEmpty(fundState_cjxjkx) ? "" : fundState_cjxjkx);
                    intent_cj.putExtra("shareClass",
                            TextUtils.isEmpty(shareClass_cjxjkx) ? "" : shareClass_cjxjkx);
                    intent_cj.putExtra("fundrisklevel",
                            TextUtils.isEmpty(fundrisklevel_cjxjkx) ? "" : fundrisklevel_cjxjkx);

                    activity.startActivity(intent_cj);
                    break;
                case R.id.rl_zh_layout://智慧
                    if (StringUtils.isNullOrEmpty(activity.getUserLevel())) {//未做评测
                        activity.startRiskActivity(null);
                    } else {
                        activity.startActivity(new Intent().setClass(activity, AssetsActivity.class));
                    }
                    break;
                case R.id.rl_jj_val://全部资产
                    AnalyticsEventUtils.toClickTotalAssetEvent(getActivity());
                    activity.startActivity(new Intent().setClass(activity, AssetsFundActivity.class));
                    break;
                case R.id.rl_dt_layout://定投
                    activity.startActivity(new Intent().setClass(activity, FixInvestmentAllActivity.class));
                    break;
                case R.id.ll_transaction_search://交易查询
                    activity.startActivity(new Intent().setClass(activity, SearchTradeNewActivity.class));
                    break;
                case R.id.rl_total_incom_layout:
                    activity.showTotalIncomAlert(activity.getString(R.string.total_incom_desc));
                    break;
//                case R.id.ll_yesterday_income_container:
//                    showTotalIncomAlert(activity.getString(R.string.yesterday_incom_desc));
//                    break;
                case R.id.civ_account_user_head:
                case R.id.tv_user_name:
                case R.id.rl_account_title:
                    intent = new Intent(activity, UserSettingActivity.class);
                    startActivity(intent);
                    break;
            }
        }
    }

    /**
     * 打开基金详情页面
     */
    private void startFundDatile(QueryFundInfoBean.DataBean fundDataBean) {
        if (fundDataBean == null) {
            return;
        }
        Intent intent = new Intent().setClass(activity, FundDetailActivity.class);
        intent.putExtra("fundcode", fundDataBean.getFundcode());
        intent.putExtra("fundname", fundDataBean.getFundname());
        intent.putExtra("mainTitle", fundDataBean.getFundname() + " " + fundDataBean.getFundcode());
        intent.putExtra("subTitle", fundDataBean.getFundstateDescription());
        intent.putExtra("fundType", fundDataBean.getFundtype());
        startActivity(intent);
    }

    private void parseJson(QueryUserAssetsBean bean) {
        if (bean == null) {
            return;
        }
        sTotalAccount = bean.getData().getTotalAssets();
        if (StringUtils.isNullOrEmpty(bean.getData().getYesterdayIncome()) || "null".equals(bean.getData().getYesterdayIncome())) {
            sYesterDayIncome = "0.00";
        } else {
            sYesterDayIncome = StringUtils.insertComma(bean.getData().getYesterdayIncome(), -1) + "";
        }
        if (StringUtils.isNullOrEmpty(bean.getData().getTotalIncome()) || "null".equals(bean.getData().getTotalIncome())) {
            sTtotalincome = "0.00";
        } else {
            sTtotalincome = StringUtils.insertComma(bean.getData().getTotalIncome(), -1) + "" + "";
        }
        try {
            if (StringUtils.isNullOrEmpty(sTotalAccount) || "null".equals(sTotalAccount)) {
                tv_total_account_decimal_val.setText(".00");
                sTotalAccount = "0";
            } else {
                if (sTotalAccount.contains(".")) {
                    tv_total_account_decimal_val.setText("" + sTotalAccount.substring(sTotalAccount.lastIndexOf(".")));
                    sTotalAccount = sTotalAccount.substring(0, sTotalAccount.lastIndexOf("."));
                }
                sTotalAccount = StringUtils.insertComma(sTotalAccount, 0);
            }
            if (image_is_show_total_account.getTag() == null || "show".equals(image_is_show_total_account.getTag().toString())) {
                tv_total_account_val.setText("" + sTotalAccount);
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (StringUtils.isNullOrEmpty(bean.getData().getTotalAtLoadRecords()) || "null".equals(bean.getData().getTotalAtLoadRecords())) {
            tv_open_ztzc_val.setText("0个");//客户在途资产数量
        } else {
            tv_open_ztzc_val.setText(StringUtils.insertComma(bean.getData().getTotalAtLoadRecords(), -1) + "个");
        }
        if (StringUtils.isNullOrEmpty(bean.getData().getTotalBuyPlanRecords()) || "null".equals(bean.getData().getTotalBuyPlanRecords())) {
            tv_dt_val.setText("0个");//客户总定投数量
        } else {
            tv_dt_val.setText(StringUtils.insertComma(bean.getData().getTotalBuyPlanRecords(), -1) + "个");
        }
        if (StringUtils.isNullOrEmpty(bean.getData().getWisdomInvestAssets()) || "null".equals(bean.getData().getWisdomInvestAssets())) {
            sZHAccount = "0.00";
        } else {
            sZHAccount = StringUtils.insertComma(bean.getData().getWisdomInvestAssets(), -1) + "";
        }
        if (StringUtils.isNullOrEmpty(bean.getData().getFundTotalAssets()) || "null".equals(bean.getData().getFundTotalAssets())) {
            sJJAccount = "0.00";
        } else {
            sJJAccount = StringUtils.insertComma(bean.getData().getFundTotalAssets(), -1) + "";
        }
        BigDecimal decimalCJXJKX = new BigDecimal(0);

        fundName_xjkx = null;
        fundState_xjkx = null;
        fundstateDescription_xjkx = null;
        fundName_cjxjkx = null;
        fundState_cjxjkx = null;
        fundstateDescription_cjxjkx = null;
        fundType_xjkx = null;
        fundType_cjxjkx = null;
        shareClass_xjkx = null;
        shareClass_cjxjkx = null;
        fundrisklevel_xjkx = null;
        fundrisklevel_cjxjkx = null;
        String sXJKXCurrentRemainShare = null;// 现金快线代码 482002 的资产
        String sCJXJKXCurrentRemainShare = null;// 超级现金快线 000677 的资产

        sXJKXCurrentRemainShare = bean.getData().getCashExpressProperty();// 现金快线代码 482002 的资产
        sCJXJKXCurrentRemainShare = bean.getData().getSuperCashExpressProperty();// 超级现金快线 000677 的资产
        if (!StringUtils.isNullOrEmpty(sXJKXCurrentRemainShare) && !"null".equals(sXJKXCurrentRemainShare)) {
            sXJKXCurrentRemainShare = StringUtils.insertComma(sXJKXCurrentRemainShare, -1);
        } else {
            sXJKXCurrentRemainShare = "0.00";
        }
        if (!StringUtils.isNullOrEmpty(sCJXJKXCurrentRemainShare) && !"null".equals(sCJXJKXCurrentRemainShare)) {
            sCJXJKXCurrentRemainShare = StringUtils.insertComma(sCJXJKXCurrentRemainShare, -1);
        } else {
            sCJXJKXCurrentRemainShare = "0.00";
        }
        if (bean.getData().getList() != null) {
            for (QueryUserAssetsBean.DataBean.ListBean mod : bean.getData().getList()) {
                try {
                    if (HostConstant.XJKJ_CODE.equals(mod.getFundCode()) && !StringUtils.isNullOrEmpty(mod.getFundCode())) {//现金快线
                        fundName_xjkx = mod.getFundName();
                        fundState_xjkx = mod.getFundStateId();
                        fundstateDescription_xjkx = mod.getFundstateDescription();
                        fundType_xjkx = mod.getFundType();
                        shareClass_xjkx = mod.getShareClass();
                        fundrisklevel_xjkx = mod.getFundrisklevel();
                        continue;
                    } else if (HostConstant.CJXJKJ_CODE.equals(mod.getFundCode()) && !StringUtils.isNullOrEmpty(mod.getFundCode())) {//超级现金快线
                        fundName_cjxjkx = mod.getFundName();
                        fundState_cjxjkx = mod.getFundStateId();
                        fundstateDescription_cjxjkx = mod.getFundstateDescription();
                        fundType_cjxjkx = mod.getFundType();
                        shareClass_cjxjkx = mod.getShareClass();
                        fundrisklevel_cjxjkx = mod.getFundrisklevel();
                        continue;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        sHomeCashTotal = sXJKXCurrentRemainShare;
        sHomeSuperCashTotal = sCJXJKXCurrentRemainShare;

        if (image_is_show_total_account.getTag() == null || "show".equals(image_is_show_total_account.getTag().toString())) {
            tv_yesterday_income_val.setText("" + sYesterDayIncome);
            tv_total_income_val.setText("" + sTtotalincome);
            tv_xjkx_val.setText("" + sHomeCashTotal);
            tv_cjxjkx_val.setText("" + sHomeSuperCashTotal);
            tv_zh_val.setText("" + sZHAccount);
            tv_jj_val.setText("" + sJJAccount);
        }
    }


    @Override
    public void onHeaderRefresh(PullToRefreshView view) {
        initData(true);
    }

    private void refreshComplete() {
        pullToRefreshView.onHeaderRefreshComplete();
    }

    public void setIsShowTotalAccount(boolean flag) {
        if (!flag) {
            image_is_show_total_account.setTag("notshow");
            tv_total_account_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_total_account_decimal_val.setVisibility(View.GONE);

            tv_yesterday_income_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_total_income_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_xjkx_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_cjxjkx_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_zh_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            tv_jj_val.setText(MentorConst.NOT_SHOW_ACCOUNT_STR);
            image_is_show_total_account.setImageResource(R.drawable.ic_home_show_account_white);
        } else {
            image_is_show_total_account.setTag("show");
            tv_total_account_val.setText("" + (StringUtils.isNullOrEmpty(sTotalAccount) ? "" : sTotalAccount));
            tv_total_account_decimal_val.setVisibility(View.VISIBLE);

            tv_yesterday_income_val.setText(sYesterDayIncome);
            tv_total_income_val.setText(sTtotalincome);
            tv_xjkx_val.setText(sHomeCashTotal);
            tv_cjxjkx_val.setText(sHomeSuperCashTotal);
            tv_zh_val.setText(sZHAccount);
            tv_jj_val.setText(sJJAccount);

            image_is_show_total_account.setImageResource(R.drawable.ic_home_no_show_account_white);
        }
    }

    /**
     * 解析返回的 用户风险等级json
     */
    private void parseJson_level(QueryRiskLevelBean bean) {
        if (bean == null) {
            return;
        }
        String userRiskLevleName = bean.getData().getLevelName();
        if (StringUtils.isNullOrEmpty(userRiskLevleName)) {
            tv_no_risk.setVisibility(View.VISIBLE);
            return;
        }
        tv_no_risk.setVisibility(View.GONE);
    }

    @Subscribe
    public void onEvent(InterfaceCallback ic) {
        if (ic == null || ic.getObj() == null) {
            return;
        }
        Object obj = ic.getObj();
        String sCallBackType = ic.getCallBackType();

        if (HostConstant.QUERY_USER_ASSETS.equals(obj)) {
            if (InterfaceCallback.SUCCESS.equals(sCallBackType)) {
//                Log.e("CallBack","Account"+"用户个人资产获取成功");
                parseJson(getQueryUserAssetsBean());
                refreshComplete();
            }
        } else if (HostConstant.QUERY_RISK_LEVEL.equals(obj)) {
            if (InterfaceCallback.SUCCESS.equals(sCallBackType)) {
//                Log.e("CallBack","Account"+"用户风险等级获取成功");
                parseJson_level(getQueryRiskLevelBean());
                refreshComplete();
            } else {
//                Log.e("CallBack","Account"+"用户个人资产获取失败");
                refreshComplete();
            }
        }
    }

    //////////////////////通知HomeActivity获取数据
    private void queryRiskLevelHome() {
        ((HomeActivity) activity).queryRiskLevel();
    }

    private void queryUserAssetsHome() {
        ((HomeActivity) activity).queryUserAssets();
    }

    private void queryFundInfoHome(String fundCode) {
        ((HomeActivity) activity).queryFundInfo(fundCode);
    }
    ///////////////////////获取HomeActivity里的 个人资产、风险评测对象

    /**
     * 风险评测
     *
     * @return
     */
    private QueryRiskLevelBean getQueryRiskLevelBean() {
        return ((HomeActivity) activity).getQueryRiskLevelBean();
    }

    /**
     * 个人资产
     *
     * @return
     */
    private QueryUserAssetsBean getQueryUserAssetsBean() {
        return ((HomeActivity) activity).getQueryUserAssetsBean();
    }

    /**
     * 获取基金详情--现金快线
     *
     * @return
     */
    private QueryFundInfoBean.DataBean getXJKJDataBean() {
        QueryFundInfoBean bean = ((HomeActivity) activity).getXJKJDataBean();
        return bean == null ? null : bean.getData();
    }

    /**
     * 获取基金详情--超级现金快线
     *
     * @return
     */
    private QueryFundInfoBean.DataBean getCJXJKJDataBean() {
        QueryFundInfoBean bean = ((HomeActivity) activity).getCJXJKJDataBean();
        return bean == null ? null : bean.getData();
    }
}
